<template>
	<div>
		<mt-header fixed title="查扣地址">
		  <router-link to="/my" slot="left">
		    <mt-button icon="back">返回</mt-button>
		  </router-link>
		</mt-header>
		<div class="amap-page-container">
		   <!-- <el-amap :vid="'amap-vue'"> -->
		      <el-amap-search-box class="search-box" :search-option="searchOption" :on-search-result="onSearchResult"></el-amap-search-box>
		      <el-amap vid="amapDemo" :center="mapCenter" :zoom="12" class="amap-demo">
		        <el-amap-marker v-for="marker in markers" :position="marker" ></el-amap-marker>
		      </el-amap>
	      <!-- </el-amap> -->
	    </div>
		<br/> 
	</div>	
</template>
<script type="text/javascript">
	export default{
    data: function() {
        return {
          markers: [
            [121.59996, 31.197646],
          ],
          searchOption: {
            // city: '上海',
            // citylimit: true
          },
          mapCenter: [104.064963, 30.570582]
        };
      },
      methods: {
        addMarker: function() {
          let lng = 121.5 + Math.round(Math.random() * 1000) / 10000;
          let lat = 31.197646 + Math.round(Math.random() * 500) / 10000;
          this.markers.push([lng, lat]);
        },
        onSearchResult(pois) {
          let latSum = 0;
          let lngSum = 0;
          if (pois.length > 0) {
            pois.forEach(poi => {
              let {lng, lat} = poi;
              lngSum += lng;
              latSum += lat;
              this.markers.push([poi.lng, poi.lat]);
            });
            let center = {
              lng: lngSum / pois.length,
              lat: latSum / pois.length
            };
            this.mapCenter = [center.lng, center.lat];
          }
        }
      }
    };
</script>
<style lang="less">
	.amap-wrapper {
	  width: 100%;
	  height: 300px;
	}
	 .amap-demo {
      height: 300px;
      width: 100%;
    }

    .search-box {
      position: absolute;
      top: 25px;
      left: 10px;
      width: 90%;
    }

    .amap-page-container {
      position: relative;
    }
</style>